<template class="page-box">
  <div>

    <el-row class="el-row">
      <el-col :span="24">
        <template>
          <el-carousel :interval="4000" type="card" height="200px">
            <el-carousel-item v-for="item in swipes" :key="item.id">
              <img :src="item.img" class="img">
            </el-carousel-item>
          </el-carousel>
        </template>
      </el-col>
    </el-row>
    <!--    商品界面-->
    <div style="background: white;border-radius: 5px;line-height: 40px;text-align: center">精选商品</div>

    <div class="goodsList">
      <div class="grid-content" v-for="(goods,i) in goodsList" :key="i">
        <div class="goodsItem" >
          <img class="goodsImg" src="../../public/static/yf.jpeg">
          <div class="price">
            <span>￥{{ goods.outPrice }}</span>
            <div  style=" text-align: center;border-radius: 16px;width: 80px; border-color:red; background:#ffb603;float: right;margin:2px 15px" @click="addOrder(goods)">
              <span class="linkRouter">
                <img src="../../public/static/payIcon.png" style="width: 15px"/>添加购物车
              </span>
            </div>
          </div>
          <div class="name" style="text-align:center;">
            {{ goods.goodsName }}
          </div>
        </div>
      </div>

    </div>


  </div>
</template>

<script>
import axios from 'axios'
import { Col } from 'element-ui';

export default {
  methods: {
    handleClick(row) {
      console.log(row);
      this.$router.push("/orderEdit");
    },
    addOrder(goods){
      if(this.cart.userId==='x'){
        this.$router.push('/login')
        return;
      }
      this.cart.goodsId=goods.id;
      console.log(goods.id)
      this.cart.price=goods.outPrice;
      
      //发送订单请求
     console.log(this.cart)
      axios({
        method: "post",
        url: "http://localhost:8088/addCart",
        params: this.cart
      }).then(resp=>{
        if(resp.data!=''){
          // this.selectAll();
          this.$message({
            message: '添加成功！',
            type: 'success'
          });
          this.$router.push('/shoppingCart')

        }
      })
    }

  },
  created() {
    axios.get(`http://localhost:8088/scan`).then(response => {
      this.$set(this, 'goodsList', response.data)
    })


  },
  data() {
    return {

      cart:{
        goodsId:'',
        price:0,
        count:1,
        userId:JSON.parse(sessionStorage.getItem('user'))===null?'x':JSON.parse(sessionStorage.getItem('user')).id
      },

      goodsList: [],


      swipes: [{
        id: 1,
        img: './static/goods04.png'
      },
        {
          id: 2,
          img: './static/goods02.png'
        },
        {
          id: 3,
          img: './static/yf1.webp'
        }
      ]
    }
  }
}
</script>
<style lang="css">

.linkRouter{
  font-size:8px;
  margin: auto;
  margin: 0 0 9px 0;
  cursor: pointer;
}
.goodsList {
  margin: auto;
  /* width: 80%; */
  flex-wrap: wrap;
  display: flex;
}

.span {
  color: #ccc;
  font-size: 14px;
  margin-left: 7px;
  text-decoration: line-through;
}

.name {
  font-size: 14px;
  line-height: 25px;
  padding-bottom: 7px;
  padding-top: 10px;
}

.goodsImg {
  width: 80%;
  height: 150px;
  display: block;
  margin: auto;
}

.price {
  color: red;
  font-size: 18px;

}

.goodsItem {
  background: white;

  margin: 13px;
  border-radius: 5px;
}

.img {

  background-size: cover;
  height: 100%;
  width: 100%;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}

.el-row {
  margin-bottom: 20px;
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #ffffff;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  width: 16%;
  padding: 20px 20px;
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

</style>